// stream.h

// Copyright (C) 2010  traxex

// Author: 	traxex <traxex@yahoo.cn>
// Created: 	16 Aug 2010
// Version: 	1.0

#pragma once

namespace traxex{
namespace cuda{

class Stream{
    cudaStream_t	id;
  public:
    Stream(){
        _safecall( cudaStreamCreate(&id));
    }
    ~Stream(){
        _safecall( cudaStreamDestroy(id));
    }
    operator cudaStream_t(){
        return id;
    }
    bool finished(){
        cudaError_t stat = cudaStreamQuery( id);
        if( stat == cudaSuccess)  
            return true;
        if( stat != cudaErrorNotReady) 
            _safecall( cudaStreamQuery( id));	//emit error msg
        return false;
    }
    void wait(){
        _safecall( cudaStreamSynchronize(id));
    }
};

}
}
